<?php
	class SystemProceduresController extends Controller
	{
		public $page_title = LANG_SYSTEM_PROCEDURES;
		public $layout = 'main';
		public $module = 'administration';
		public $helpers = array ('html', 'htmlx', 'toolbars', 'grids|index');
		public $name = 'system_procedures';
		
		function index()
		{
			//$this->data[$this->name] = $this->controller_model->ListItemsPaged($this->request->get);
			$parameters = array('num_rows');
			$this->data[$this->name] = $this->controller_model->ListItems($this->request->get, 'sp_system_procedures_list_paged',$parameters);
			$this->data[num_rows] = $parameters[num_rows];
		}
		
		function edit($id)
		{
		
			$this->data[$this->name] = $this->controller_model->Get($id);			
			if (!empty($this->request->post))
			{
				
				if ($this->controller_model->Update($this->request->post))
				{
					if (isset($this->request->post[execute]))
					{
						$this->controller_model->Execute(array(), $this->request->post[name]);
					}
					$this->Redirect($this->name);
				}
				else
				{
					$this->data[$this->name] = $this->request->post;				
				}
			}			
		}
		
		function add()
		{

					
			if (!empty($this->request->post))
			{
				if ($this->controller_model->Update($this->request->post))
				{
					$this->Redirect($this->name);
				}
				else
				{
					$this->data[$this->name] = $this->request->post;				
				}
			}
			else
			{

			}	
		}
		
		function view($id)
		{
			$this->data[done] = 0;
			$this->data[$this->name] = $this->controller_model->Get($id);
			if (!empty($this->request->post))
			{
				$this->controller_model->Execute(array(), $this->data[$this->name][name]);
				$this->data[done] = 1;
			}
		}
		
		function delete($id, $confirm = 0)
		{ 
			if ($confirm)
			{
				$this->controller_model->Delete($id);
				$this->Redirect($this->name);
			}
			else
			{
				$this->layout = "empty";
				$this->data[$this->name][id] = $id;
			}
		}
	}
?>